#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> b(20005);
struct DSU{
    vector<int> parent, size;
    DSU(int n) {
        parent.resize(n + 1);
        size.resize(n + 1, 1);
        for(int i = 0; i <= n; i++) {
            parent[i] = i;
        }
    }
    int find(int x) {
        if(parent[x] != x) {
            parent[x] = find(parent[x]);
        }
        return parent[x];
    }
    void unite(int x, int y) {
        int fx = find(x), fy = find(y);
        if(fx == fy) {
            return;
        }
        if(size[fx] < size[fy]) {
            swap(fx, fy);
        }
        parent[fy] = fx;
        size[fx] += size[fy];
    }
    bool check(int x, int y) {
        if(find(x) == find(y)) {
            return true;
        }
        return false;
    }
};
struct person{
    int x, y, z;
    person(int a, int b, int c) : x(a), y(b), z(c) {}
};
bool compare(person& x, person& y) {
    return x.z > y.z;
}

vector<person> v;
int main() {
    int n, k;
    cin >> n >> k;
    DSU a(n + 1);
    for(int i = 0; i < k; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        v.push_back(person(x, y, z));
    }
    sort(v.begin(), v.end(), compare);
    for(int i = 0; i < k; i++) {
        if(a.check(v[i].x, v[i].y)) {
            cout << v[i].z << endl;
            return 0;
        }
        else {
            if(!b[v[i].x]) {
                b[v[i].x] = v[i].y;
            }else {
                a.unite(b[v[i].x], v[i].y);
            }
            if(!b[v[i].y]) {
                b[v[i].y] = v[i].x;
            }else {
                a.unite(b[v[i].y], v[i].x);
            }
        }
    }
    cout << 0 << endl;
    return 0;
}